<template>
    <div>
        <a-modal
            :width="1000"
            title="选择人员"
            :visible="manualVisible"
            :confirm-loading="confirmLoading"
            @ok="manualHandleOk"
            @cancel="manualVisible = false"
        >
            <commpVxeTable
                v-if="parametersData.type == '选人'"
                :key="compSelectorkey"
                :config="dataTableConfig" 
                :columns="columnsVxe" 
                :formItem="formItem"
                @checkboxChange="checkboxChange"
                ref="acceptanceRegistrationRef"
            >
            </commpVxeTable>
            <commpVxeTable
                v-if="parametersData.type == '选模板'"
                :key="compSelectorkey"
                :config="mouldConfig" 
                :columns="mouldColumns" 
                :formItem="mouldFormItem"
                @checkboxChange="checkboxChange"
                ref="acceptanceRegistrationRef"
            >
            </commpVxeTable>
        </a-modal>
        
    </div>
</template>
<script>
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import assessCheckApi from './service/api'
import {xpHcyByHandServe } from './service/index'
export default {
    components:{
        commpVxeTable,
    },
    props:{
        parametersData:{
            type:[Array,Object],
            default: () => {},
            required:false
        }
    },
    watch:{
        parametersData:{
            handler (newval, oldVal) {
                //console.log('~~~~~~~~~~@选人的======',newval)
                this.transferValue = newval
                this.compSelectorkey = Date.now()
                
            },
            immediate: true,
            deep: true
        }
    },
    data(){
        return{
            formItem:[
                {
                    label: '真实姓名',
                    model: 'realname',
                }
            ],
            columnsVxe:[
                { 
                    type: 'checkbox', 
                    width: 60 ,
                    fixed: 'left'
                },{
                    title: '真实姓名', //列头显示文字
                    field: 'realname',
                    fixed: 'left',
                },{
                    title: '工作单位', //列头显示文字
                    field: 'fgzdw',
                },{
                    title: '所属库', //列头显示文字
                    field: 'fssk',
                },{
                    title: '所属区域', //列头显示文字
                    field: 'fssqy',
                },{
                    title: '擅长领域',
                    field: 'fszly',
                }], 
            dataTableConfig:{
                api: assessCheckApi.queryHcyPageList,
                rowId: 'id',
                fywflcode:'002',
                height:300,
                paramet:{
                    ...this.parametersData
                }
            },
            mouldFormItem:[
                {
                    label: '模板标题',
                    model: 'fmbbt',
                }
            ],
            mouldConfig:{
                api: assessCheckApi.modelPageList,
                rowId: 'id',
                fywflcode:'002',
                height:300
            },
            mouldColumns:[{
                    title: '模板标题', //列头显示文字
                    dataIndex: 'fmbbt',
                    key: 'fmbbt',
                },{
                    title: '模板类型1', //列头显示文字
                    dataIndex: 'fmblx1',
                    key: 'fmblx1',
                }
            ],
            manualVisible:false,
            confirmLoading:false,
            transferValue:{},
            checkboxKey:[],
            compSelectorkey:null
        }
    },
    watch:{

    },
    mounted(){
        
    },
    updated(){
        this.$emit('updatedSuccess')
    },
    methods:{
        checkboxChange(val){
            this.checkboxKey = []
            if(val.length){
                val.forEach(item => {
                    this.checkboxKey.push(item.id)
                });
            }
        },
        manualHandleOk(){
            if(!this.checkboxKey.length){
                this.$message.warning('请选择人员')
                return false
            }
            this.confirmLoading = true
            xpHcyByHandServe({hcyids:this.checkboxKey.join(','),
                fusertype:this.parameter.fusertype,
                jssj:this.parameter.jssj,
                kssj:this.parameter.jssj,
                sqsxid:this.parameter.sqsxid}).then(res=>{
                    this.confirmLoading = false
                    if(res.code == 200){
                        this.$emit('manualSuccess')
                        this.manualVisible = false
                    }
                })
            }
    }
}
</script>
<style>

</style>